package com.bootdo.change.controller;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.bootdo.change.entity.ChangeTask;
import com.bootdo.change.entity.ChangeTaskInfoVo;
import com.bootdo.change.service.ChangeTaskInfoService;
import com.bootdo.change.service.ChangeTaskService;
import com.bootdo.change.service.MalChangeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.goods.domain.TGoodsAllocationDO;
import com.bootdo.goods.domain.TGoodsShelfDO;
import com.bootdo.goods.service.TGoodsAllocationService;
import com.bootdo.goods.service.TGoodsShelfService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;

/***
 * 手动调仓
 * @author wlst
 *
 */
@Controller
@RequestMapping("/change/changeMsg")
public class MalChangeController {

	@Autowired
	private MalChangeService malChangeService;
	@Autowired
	private TGoodsShelfService tGoodsShelfService;
	@Autowired
	private TGoodsAllocationService tGoodsAllocationService;
	@Autowired
	private ChangeTaskService changeTaskService;
	@Autowired
	private ChangeTaskInfoService changeTaskInfoService;
//	@GetMapping()
//	//@RequiresPermissions("change:changeMsg:changeMsg")
//	String TGoodsAllocation(@RequestParam(required = false) Long providerId,Model model){
//		System.out.println("providerId:"+providerId);
//		model.addAttribute("providerId",providerId);
//	    return "change/changeMsg/changeMsg";
//	}
//	
//	@ResponseBody
//	@GetMapping("/list")
////	@RequiresPermissions("goods:tGoodsShelf:tGoodsShelf")
//	public PageUtils list(@RequestParam Map<String, Object> params){
//
//		System.out.println("params:"+JSON.toJSON(params));
//		//查询列表数据
//        Query query = new Query(params);
//		List<TGoodsShelfDO> tGoodsShelfList = tGoodsShelfService.list(query);
//		int total = tGoodsShelfService.count(query);
//		PageUtils pageUtils = new PageUtils(tGoodsShelfList, total);
//		return pageUtils;
//	}
//
//
//	@GetMapping("/queryAllocation/{shelfId}")
//	String queryAllocation(@PathVariable("shelfId") Long shelfId,Model model){
//		TGoodsShelfDO tGoodsShelf = tGoodsShelfService.get(shelfId);
//		model.addAttribute("shelfId",shelfId);
//		model.addAttribute("tGoodsShelf",tGoodsShelf);
//		return "change/changeMsg/shelfAllocation";
//	}
//	

	
	/***
	 * 调仓记录列表页
	 */
	@GetMapping("/selectList")
	public String selectList(){
		
		return "change/changeMsg/selectList";
	}
	/***
	 * 调仓记录查询
	 */
	@ResponseBody
	@GetMapping("/listAll")
	public PageUtils listAll(@RequestParam Map<String, Object> params){

		System.out.println("params:"+JSON.toJSON(params));
		//查询列表数据
        Query query = new Query(params);
		List<ChangeTaskInfoVo> tGoodsShelfList = changeTaskInfoService.listInfo(query);
		int total = changeTaskInfoService.count(query);
		PageUtils pageUtils = new PageUtils(tGoodsShelfList, total);
		return pageUtils;
	}
	
/***
 * 详细列表
 * @param Id
 * @param model
 * @return
 */
	@GetMapping("/selectInfo")
	//@RequiresPermissions("put:putStorageDetail:putStorageDetail")
	String selectInfoList(@RequestParam(required = false) String id,Model model){
		System.out.println("id:"+id);
		model.addAttribute("id",id);
	
		model.addAttribute("putStorageDO",changeTaskInfoService.get(id));
	    return "change/changeMsg/selectInfoList";
	}
	
	/***
	 * 详细列表查询
	 */
	@ResponseBody
	@GetMapping("/listInfoAll")
	public PageUtils listInfoAll(@RequestParam Map<String, Object> params){

		System.out.println("params:"+JSON.toJSON(params));
		//查询列表数据
        Query query = new Query(params);
		List<ChangeTaskInfoVo> tGoodsShelfList = changeTaskInfoService.list(query);
		int total = changeTaskInfoService.count(query);
		PageUtils pageUtils = new PageUtils(tGoodsShelfList, total);
		return pageUtils;
	}
}
